from django.db import models

from utils.base import BaseModel


class Project(BaseModel):
    name = models.CharField(max_length=50, help_text='项目名称')
    desc = models.CharField(max_length=200, help_text='项目描述', verbose_name='项目描述')
    url = models.CharField(max_length=200, help_text='机器人消息发送地址', blank=True, default='')
    user = models.ManyToManyField('users.User')

    class Meta:
        db_table = 'tb_project'
        verbose_name = '项目表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class ProjectAppeal(BaseModel):
    project = models.ForeignKey(Project, on_delete=models.CASCADE)
    user = models.ForeignKey('users.User', on_delete=models.CASCADE)
    status = models.BooleanField(verbose_name='审核状态', default=False)

    class Meta:
        db_table = 'tb_project_appeal'
        verbose_name = '项目成员申请表'

    # def info(self):
    #     """
    #     返回项目信息
    #     """
    #     return [
    #         {'name': '测试环境数量', 'value': self.test_envs.count()},
    #         {'name': '测试场景数量', 'value': self.test_scenes.count()},
    #         {'name': '测试计划数量', 'value': self.test_plans.count()},
    #         {'name': '接口数量', 'value': self.interfaces.count()},
    #         {'name': '定时任务数量', 'value': 0},
    #         {'name': '执行记录数量', 'value': Record.objects.filter(plan__project=self).count()},
    #     ]
    #
    # def bugs(self):
    #     """
    #     返回项目的bugs统计信息
    #     """
    #     return [
    #         {'name': 'Bug总数量', 'value': self.bug_set.count()},
    #         {'name': '未处理Bug数', 'value': self.bug_set.filter(status='未处理').count()},
    #         {'name': '处理中Bug数', 'value': self.bug_set.filter(status='处理中').count()},
    #         {'name': '处理完Bug数量', 'value': self.bug_set.filter(status='处理完').count()},
    #         {'name': '无效Bug数', 'value': self.bug_set.filter(status='无效bug').count()},
    #     ]
    #




